package 栈和队列;

import java.util.EmptyStackException;

class LLNode {
    private LLNode next;
    private int data;

    public LLNode(int data) {
        this.data = data;
    }

    public LLNode getNext() {
        return next;
    }

    public void setNext(LLNode next) {
        this.next = next;
    }

    public Integer getData() {
        return data;
    }

    public void setData(int data) {
        this.data = data;
    }

    public void addNode(LLNode newNode) {
        // TODO Auto-generated method stub
        if (this.next == null) {
            this.setNext(newNode);
        } else {
            this.getNext().addNode(newNode);
        }

    }

    public void printNode() {
        System.out.println(this.getData());
        if (this.getNext() != null) {

            this.getNext().printNode();
        }
    }

}

class LinkNode {
    private LLNode headNode;

    public void addNode(int data) {
        if (headNode == null) {
            headNode = new LLNode(data);
        } else {
            LLNode newNode = new LLNode(data);
            this.headNode.addNode(newNode);
        }
    }

    public void printNode() {
        this.headNode.printNode();
    }
}

public class LinkBuildStack {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        LinkNode root = new LinkNode();
        root.addNode(1);
        root.addNode(2);
        root.addNode(3);
        root.printNode();
		/*LLStack stack = new LLStack();
		stack.Push(1);
		stack.Push(2);
		stack.Push(3);
		while(stack.isEmpty()==false) {
			System.out.println(stack.pop());
		}*/

    }

}
